package com.xuecheng.content.controller;

import com.xuecheng.api.content.TeachplanApi;
import com.xuecheng.api.content.model.dto.TeachplanDTO;
import com.xuecheng.api.content.model.vo.TeachplanVO;
import com.xuecheng.content.common.util.SecurityUtil;
import com.xuecheng.content.convert.TeachplanConvert;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 课程计划 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
@RequestMapping
public class TeachplanController implements TeachplanApi {

    @Autowired
    private TeachplanService  teachplanService;


    @GetMapping("teachplan/{courseId}/tree-nodes")
    public TeachplanDTO queryTreeNodesByCourseId(@PathVariable Long courseId) {

        //1. 获得公司Id
        Long companyId = SecurityUtil.getCompanyId();

        //2. 调用service获得 dto数据
        TeachplanDTO teachplanDTO = teachplanService.queryTreeNodesByCourseId(courseId, companyId);

        return teachplanDTO;

    }
    //新增和修改
    @PostMapping("teachplan")
    public TeachplanDTO createOrModifyTeachPlan(@RequestBody TeachplanVO teachplanVO) {

        //1. 获得公司Id
        Long companyId = SecurityUtil.getCompanyId();

        //2. 将vo数据转为 dto 数据
        TeachplanDTO dto = TeachplanConvert.INSTANCE.vo2dto(teachplanVO);

        //2.调用service获得 dto数据
        TeachplanDTO result = teachplanService.createOrModifyTeachPlan(dto, companyId);

        return result;

    }

    @DeleteMapping("teachplan/{teachplanId}")
    public void removeTeachPlan(@PathVariable Long teachplanId) {

        // 1.获得公司Id
        Long companyId = SecurityUtil.getCompanyId();

        // 2.调用service方法
        teachplanService.removeTeachPlan(teachplanId,companyId);
    }
}
